let rec power x n =
  match n with
    0 -> 1
    |n when n < 0 -> invalid_arg " puissance negative"
    |n -> x * power x (n-1);;
power 2 10 ;;
 
let rec application poly x =
  match poly with
    [] -> 0
    | e::l -> let (e1,e2)= e in
     e1 *  power x e2 + application l x;;
 application [(2,2);(2,3);(4,4)] 2;;

let rec add p1 p2 =
  match p1 with
    [] -> p2
    | e1::l1  -> match p2 with 
        [] -> p1
	|e2::l2 -> let (e11,e12) = e1 and (e21, e22) = e2 in 
            match e12 with
                e12 when e12 = e22 -> (e11 + e21, e12):: add l2 l1
                | e12 when e12 < e22 -> (e11,e12):: add l1 p2
                | _ -> (e21,e22):: add p1 l2;; 
add [(1,2);(2,6);(7,8);(2,12)] [(1,4);(3,6);(1,9)];;

let rec soustract p1 p2 = 
  match p1 with
    [] -> p2
    | e1::l1  -> match p2 with 
        [] -> p1
	|e2::l2 -> let (e11,e12) = e1 and (e21, e22) = e2 in 
            match e12 with
                e12 when e12 = e22 -> (e11 - e21, e12):: soustract l1 l2
                | e12 when e12 < e22 -> (e11,e12):: soustract l1 p2
                | _ -> (-e21,e22):: soustract p1 l2;; 
soustract [(1,2);(2,6);(7,8);(2,12)] [(1,4);(3,6);(1,9)];;


let rec deriv p1 = 
  match p1 with 
    [] -> []
    | e::l -> let (e1,e2)= e in 
        (e2*e1,e2-1):: deriv l;;  
deriv [(2,2);(2,3);(4,4)];;

